<?php

	// Files to hide in the directory listing
	// add and subtract as you please
	$hide = array(	'resources',
					'index.php',
					'.htaccess',
					'.htpasswd',
					'.DS_Store');
			
	error_reporting(E_ERROR);
	
	// When downloading force it to actually download
	// rather than just open it in the browser
	if ($_GET['download']) {
		$file = str_replace('/', '', $_GET['download']);
		$file = str_replace('..', '', $file);

		if (file_exists($file)) {
			header("Content-type: application/x-download");
			header("Content-Length: ".filesize($file)); 
			header('Content-Disposition: attachment; filename="'.$file.'"');
			readfile($file);
			die();
		}
	}
	
	$filepath = $_SERVER['SCRIPT_FILENAME'];
	$scriptname = basename($filepath);
	$readpath = str_replace($scriptname, "", $filepath);
	$handle = opendir($readpath);
	
	// If deleting
	if (isset($_GET['rmfile'])) {
		unlink($readpath . $_GET['rmfile']);
	}
	
	// If uploading
	if ($_FILES['file']) {
		$success = move_uploaded_file($_FILES['file']['tmp_name'], $_FILES['file']['name']);
	}

	while ($file = readdir($handle)) { 
		
		if ($file == "." || $file == ".." || in_array($file, $hide))  continue;
		
		$key = @filemtime($file);
		
		$files[$key] = $file;
		
	}
	
	closedir($handle); 

	// Sort our files
	@ksort($files, SORT_NUMERIC);
	$files = @array_reverse($files);

?>

	<!DOCTYPE html>
	<html>
	
		<head>
			<title>Arka Space</title>
			<link rel="stylesheet" type="text/css" href="resources/styles.css" />
		</head>
		
		<body style="background-color: #999999">
			<h1><font color="#FFFFFF">File Transfer</font></h1>

			<?php $baseurl = $_SERVER['PHP_SELF']; ?>

			<font color="#00FF00">
			<table border="2" cellspacing="5" cellpadding="5">

				<?php
					$arsize = sizeof($files);
				
					for ($i=0; $i<$arsize; $i++) {
					
						$ext = strtolower(substr($files[$i], strrpos($files[$i], '.')+1));
		
						$filename = stripslashes($files[$i]);
						$fileurl = $files[$i];
						if (strlen($filename) > 43) {
							$filename = substr($files[$i], 0, 40) . '...';
						}
				?>

							<tr>
								<td><img src="resources/theIcon.JPG" /></td>
								<td><a href="./index.php?download=<?php echo $filename; ?>"><?php echo $filename; ?></a></td>
								<td><?php echo round(filesize($leadon.$files[$i])/1024); ?>KB</td>
								<td><?php echo date ("d/m/y", filemtime($leadon.$files[$i]));?></td>
							</tr>
						
				<?php } ?>
			
			</table>
			</font>

		</body>
		
	</html>

